package com.scau.yangsuiyu.estore.util;

import javafx.scene.control.Alert;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author suiyu_yang
 * @description 读取照片的工具类
 * @date 2019-06-19 20:59
 * @email suiyu_yang@163.com
 */
public class ImageViewUtil {

    public static void loadImage(ImageView photoImageView, String url) {
        File file = new File(url);
        BufferedImage bufferedImage = null;
        try {
            bufferedImage = ImageIO.read(file);
        } catch (IOException e) {
            new Alert(Alert.AlertType.ERROR, "请选择正确的图片！").showAndWait();
        }

        if (bufferedImage != null) {
            photoImageView.setImage(new Image("file:" + url));
        }
    }

}
